package org.gpp.proj1.robot.action;

import java.util.HashMap;
import java.util.Map;

public class ActionCache {
	/**
	 * The factory's unique instance
	 */
	private static ActionCache instance = null;
	
	/**
	 * The model map
	 */
	private Map<String, PartAction> actionMap;
	
	/**
	 * Default, private constructor
	 */
	private ActionCache() {
		actionMap = new HashMap<String, PartAction>();
	}
	
	/**
	 * @return The model builder's unique instance
	 */
	public static ActionCache getInstance() {
		if( instance == null ) {
			instance = new ActionCache();
		}
		
		return instance;
	}
	
	/**
	 * The action with the given name, or null if there are no
	 * actions with this name. The actions are loaded during a
	 * Part's parsing
	 */
	public PartAction getAction(String action) {
		if( actionMap.containsKey( action ) ) {
			return actionMap.get( action );
		}
		
		return null;
	}

	/**
	 * Adds an action to the action set
	 * @param action
	 */
	public void addAction(PartAction action) {
		this.actionMap.put( action.getName(), action );
	}
}
